package com.neu.servlet.klz;

import com.alibaba.fastjson.JSONObject;
import com.neu.service.klz.KindDaoService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

@WebServlet(name = "AddKindServlet", urlPatterns = {"/AddKindServlet.do"})
public class AddKindServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String k_name=request.getParameter("k_name");
        KindDaoService kindDaoService=new KindDaoService();
        boolean flag=kindDaoService.dosave(k_name);
        Map<String,Object> map=new HashMap<>();
        if(flag){
            map.put("msg","添加成功");
            String json=JSONObject.toJSONString(map);
            System.out.println(json);
            PrintWriter out=response.getWriter();
            out.print(json);
            out.close();
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
